import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#######################################################3.2.1单柱形图
# df = pd.read_excel('1.xlsx')
# x = df['部门']
# height = df['1月']
# plt.figure(figsize=(8, 4))
# plt.rcParams['font.sans-serif']='SimHei'
# plt.title('某公司各部门1月份实际支出单柱形图')
# plt.ylabel('实际支出(元)')
# for a,b in zip(x,height):
#     plt.text(a,b,'%d'%b,ha='center')
# plt.bar(x,height,0.4,color='teal')
# plt.legend(('1月'))
# plt.show()

#################################################################3.2.2簇状柱形图
# df = pd.read_excel('1.xlsx')
# plt.figure(figsize=(8, 4))
# plt.rcParams['font.sans-serif'] = 'SimHei'
# plt.title('某公司各部门1——2月份实际支出簇状柱形图')
# plt.ylabel('实际支出(元)')
# x_data = np.arange(len(df['部门']))
# height_data = []
# height_data.append(df['1月'])
# height_data.append(df['2月'])
# width = 0.4
# for i in range(len(height_data)):
#     x = x_data + i * width
#     height = height_data[i]
#     plt.bar(x, height, width)
# for a, b in zip(x, height):
#     plt.text(a, b, '%d' % b, ha='center')
# plt.xticks(x_data + 0.2, df['部门'])
# plt.legend(('1月', '2月'))
# plt.show()


##############################################################################3.2.3堆积柱形图
df = pd.read_excel('1.xlsx')
x = df['部门']
plt.figure(figsize=(8, 4))
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.ylabel('实际支出(元)')
width = 0.4
plt.bar(x,df['1月'],width,color='green')
plt.bar(x,df['2月'],width,bottom=df['1月'],color='salmon')
for a,b,c in zip(x,df['1月'],df['2月']):
    plt.text(a,b/2,'%d'%b,ha='center',va='center')
    plt.text(a,b+c/2,'%d'%c,ha='center',va='center')
plt.legend(('1月','2月'))
plt.show()